<template>
  <div class="page_padding board_write">
    <MyNavBar @goback="goback" :title="formData.recordName" />
    <van-tabs
      @click="onTabsClick"
      class="cont-tab"
      v-model="showTabs"
      line-width="35"
      line-height="2"
      title-active-color="#d80a06"
      title-inactive-color="#333333"
      border
      swipeable
      v-if="formCode === 'FORM_V3'">
      <van-tab title="单框模式填写" name="1"></van-tab>
      <van-tab title="条目化模式填写" name="2"></van-tab>
    </van-tabs>
    <div class="board_write_content">
      <div class="return-box" v-if="formData && formData.reason">退回原因： {{ formData.reason }}</div>
      <div v-if="showTabs === '1'">
        <div class="this_week" v-for="(item, index) in allData" :key="index">
          <BoardSound :listData="item" :recordTime="item.id === 'workCon' ? recordTime : ''"></BoardSound>
        </div>
      </div>
      <div v-if="showTabs === '2'">
        <div class="tem_operate">
          <span @click="operateCli">
            <van-icon name="apps-o" />
            示例&操作
          </span>
        </div>
        <div class="week_box">
          <div class="two_title1">
            <span class="two_title1_left">本周工作纪实</span>
            <span class="title_time">{{ recordTime }}</span>
          </div>
          <van-collapse v-model="activeName" accordion :border="false">
            <div class="now_week">
              <van-collapse-item
                class="now_week_one"
                :name="index"
                v-for="(daily, index) in dailyObj.nowWeekList"
                :key="index"
                :disabled="dailyObj.nowWeekList.length == 1"
                :class="{ no_collapse: dailyObj.nowWeekList.length == 1 }"
                :border="false">
                <template #title>
                  <div class="now_week_title" v-if="dailyObj.nowWeekList.length > 1">
                    <div class="now_week_title_left">
                      <span class="week_title_tips">{{ getDoubleNum(index + 1) }}</span>
                      <span class="week_title" v-show="activeName !== index">{{ daily.oneData[0].entryCont }}</span>
                    </div>
                    <div class="now_week_title_r" v-show="activeName === index">
                      <span @click.stop="collectWeek(daily, index)" v-if="daily.collectShow">
                        <van-icon name="star-o" />
                        收藏
                      </span>
                      <span @click.stop="cancelWeek(index)" class="">
                        <van-icon name="delete-o" />
                        删除
                      </span>
                    </div>
                    <!-- <div class="now_week_title_tip" v-show="activeName !== index && daily.finishStatus === '0'">
                      <i class="iconfont icon-jinxingzhong"></i>
                    </div> -->
                  </div>
                  <div class="now_week_title one" v-else>
                    <div class="now_week_title_r">
                      <span @click.stop="collectWeek(daily, index)" v-if="daily.collectShow">
                        <van-icon name="star-o" />
                        收藏
                      </span>
                    </div>
                  </div>
                </template>
                <div class="this_week" v-for="dailyTwo in daily.oneData" :key="dailyTwo.id">
                  <BoardOne
                    :listData="dailyTwo"
                    :indexObj="{ index: index, type: '1' }"
                    @btnJudge="contentJudge"></BoardOne>
                </div>
                <div class="week_input_data">
                  <div class="week_text">
                    <div class="week_text_title">工作分类</div>
                    <div class="week_input_r">
                      <van-field
                        class="week_fied_input"
                        maxlength="4"
                        v-model="daily.workTag"
                        label=""
                        placeholder="请输入或选择"
                        right-icon="arrow"
                        @click-right-icon="classifyTips(index, '1')"
                        ref="test" />
                    </div>
                  </div>
                  <div class="week_text pad_left_board">
                    <div class="week_text_title">所属类型</div>
                    <div class="week_text_r" @click="workFromPop(index, '1')">
                      <van-cell is-link :class="{ placeholder: !daily.workClassify }">
                        <template #default>
                          {{ workClassify(daily.workClassify) }}
                        </template>
                      </van-cell>
                    </div>
                  </div>
                </div>
                <div class="week_input_data">
                  <div class="week_text">
                    <div class="week_text_title">完成情况</div>
                    <div class="week_text_r">
                      <van-radio-group v-model="daily.finishStatus" direction="horizontal">
                        <van-radio name="1">已完成</van-radio>
                        <van-radio name="0">进行中</van-radio>
                      </van-radio-group>
                    </div>
                  </div>
                </div>
              </van-collapse-item>
              <div class="now_week_add">
                <div class="week_add-one m-add_l" @click="addRowsWeek">
                  <van-icon name="add-o" class="add_icon" />
                  <span>添加</span>
                </div>
                <div class="week_add-one" @click="addRowsTemplate">
                  <van-icon name="add-o" class="add_icon" />
                  <span>从模板添加</span>
                </div>
              </div>
            </div>
          </van-collapse>
        </div>

        <div class="week_box">
          <div class="two_title1">
            <span class="two_title1_left">下周工作计划</span>
          </div>
          <van-collapse v-model="activeNameNext" accordion :border="false">
            <div class="now_week">
              <van-collapse-item
                class="now_week_one"
                :name="index"
                v-for="(daily, index) in dailyObj.nextWeekList"
                :key="index"
                :disabled="dailyObj.nextWeekList.length == 1"
                :class="{ no_collapse: dailyObj.nextWeekList.length == 1 }"
                :border="false">
                <template #title>
                  <div class="now_week_title" v-if="dailyObj.nextWeekList.length > 1">
                    <div class="now_week_title_left">
                      <span class="week_title_tips">{{ getDoubleNum(index + 1) }}</span>
                      <span class="week_title" v-show="activeNameNext !== index">{{ daily.oneData[0].entryCont }}</span>
                    </div>
                    <div class="now_week_title_r" v-show="activeNameNext === index">
                      <span @click.stop="collectNextWeek(daily, index)" v-if="daily.collectShow">
                        <van-icon name="star-o" />
                        收藏
                      </span>
                      <span @click.stop="cancelNextWeek(index)" class="">
                        <van-icon name="delete-o" />
                        删除
                      </span>
                    </div>
                    <div class="now_week_title_tip" v-show="activeNameNext !== index && daily.finishStatus === '0'">
                      <i class="iconfont icon-jinxingzhong"></i>
                    </div>
                  </div>
                  <div class="now_week_title one" v-else>
                    <div class="now_week_title_r">
                      <span @click.stop="collectWeek(daily, index)" v-if="daily.collectShow">
                        <van-icon name="star-o" />
                        收藏
                      </span>
                    </div>
                  </div>
                </template>
                <div class="this_week" v-for="(dailyTwo, i) in daily.oneData" :key="i">
                  <BoardOne
                    :listData="dailyTwo"
                    :indexObj="{ index: index, type: '2' }"
                    @btnJudge="contentJudge"></BoardOne>
                </div>
                <div class="week_input_data">
                  <div class="week_text">
                    <div class="week_text_title">工作分类</div>
                    <div class="week_input_r">
                      <van-field
                        class="week_fied_input"
                        maxlength="4"
                        v-model="daily.workTag"
                        label=""
                        placeholder="请输入或选择"
                        right-icon="arrow"
                        @click-right-icon="classifyTips(index, '2')" />
                    </div>
                  </div>
                  <div class="week_text pad_left_board">
                    <div class="week_text_title">所属类型</div>
                    <div class="week_text_r" @click="workFromPop(index, '2')">
                      <van-cell is-link :class="{ placeholder: !daily.workClassify }">
                        <template #default>
                          {{ workClassify(daily.workClassify) }}
                        </template>
                      </van-cell>
                    </div>
                  </div>
                </div>
              </van-collapse-item>
              <div class="now_week_add">
                <div class="week_add-one m-add_l" @click="addNextWeek">
                  <van-icon name="add-o" class="add_icon" />
                  <span>添加</span>
                </div>
                <div class="week_add-one" @click="addNextTemplate">
                  <van-icon name="add-o" class="add_icon" />
                  <span>从模板添加</span>
                </div>
              </div>
            </div>
          </van-collapse>
        </div>
      </div>
      <!-- 问题建议 -->
      <div class="sugg_item">
        <div class="list_text_title">
          <span class="text">问题建议</span>
        </div>
        <div class="suggestion_box">
          <div class="suggestion" v-for="(item, i) in suggestionList" :key="'a' + i">
            <div class="suggestion_info" v-for="(items, index) in item.suggestionData" :key="'b' + index">
              <BoardSimple
                :listData="items"
                :title="suggestionList.length > 1 ? i + 1 : ''"
                showType="suggset"
                @deleteSug="deleteSug"
                :deleteShow="suggestionList.length"></BoardSimple>
            </div>
            <div class="suggestion_annex">
              <div class="img_video">
                <ImgUpload
                  v-bind:albumList.sync="item.suggestionalbumList"
                  :suggestionAnnex="true"
                  @temporaryStorage="temporaryStorage" />
              </div>
            </div>
          </div>
          <div class="add_box">
            <div class="add_btn" @click="addSug">
              <van-icon name="add-o" style="color: #56462c" />
              <span>添加</span>
            </div>
          </div>
        </div>
      </div>
      <!-- 附件 -->
      <div class="annex">
        <!-- 图片/视频 -->
        <div class="img_video">
          <div class="list_text_title">
            <span class="text">添加图片/视频/附件</span>
          </div>
          <ImgUpload
            v-bind:albumList.sync="formContent.recordFileList"
            @temporaryStorage="temporaryStorage"
            :isAnnex="true" />
        </div>
      </div>
      <!-- 底部 -->
      <div class="fead_boot">
        <div class="btn_li" @click="commitBoard('0')">暂存</div>
        <div class="btn_li" @click="viewBoard()">预览</div>
        <div class="btn_li" @click="commitBoard('1')">提交</div>
      </div>
    </div>
    <!-- 工作分类 -->
    <van-action-sheet
      v-model="actionShowWork"
      close-on-click-action
      @select="onSelectWork"
      :actions="classifyList"></van-action-sheet>
    <!-- 所属类型 -->
    <van-action-sheet
      v-model="actionShowStyle"
      close-on-click-action
      @select="onSelectStyle"
      :actions="taskList"></van-action-sheet>

    <van-popup v-model="templateShow" position="bottom" round>
      <TemplateAdd @cancelTemplate="templateShow = false" @templateBtn="templateBtn" v-if="templateShow" />
    </van-popup>

    <!-- 切换弹框 -->
    <van-dialog v-model="numersShow" title="提示" :show-confirm-button="false" class="tip_dialog">
      <div class="push_dia_box">
        <p class="push_dia_box_content">
          <van-icon class="icon_warn" name="warning" />
          您只需选择一种填写模式，无需两种模式都填写。
        </p>
      </div>
      <div class="push_dia_commit">
        <van-checkbox v-model="numersCheck" shape="square">不再提醒</van-checkbox>
        <span class="push_dia_commit_btn" @click="numbersCli">好的</span>
      </div>
    </van-dialog>

    <!-- 收藏弹框 -->
    <van-dialog v-model="collectDiaShow" title="提示" :show-confirm-button="false" class="tip_dialog">
      <div class="push_dia_box">
        <p class="push_dia_box_content">
          <van-icon class="icon_warn" name="warning" />
          成功收藏至个人模板，点击“从模板添加”即可快速复用收藏的内容
        </p>
      </div>
      <div class="push_dia_commit">
        <van-checkbox v-model="checkedCollect" shape="square">不再提醒</van-checkbox>
        <span class="push_dia_commit_btn" @click="btnCheck">好的</span>
      </div>
    </van-dialog>

    <van-dialog v-model="tipSubmitShow" title="提示" :show-confirm-button="false" class="tip_dialog">
      <div class="push_dia_box">
        <p class="push_dia_box_content">
          <van-icon class="icon_warn" name="warning" />
          {{ mesDia }}
        </p>
      </div>
      <div class="push_dia_commit">
        <span></span>
        <span class="push_dia_commit_btn" @click="tipSubmitShow = false">好的</span>
        <span></span>
      </div>
    </van-dialog>
  </div>
</template>

<script>
import MyNavBar from '@com/MyNavBar'
import BoardSound from '@com/BoardSound'
import BoardSimple from '@com/BoardSimple'
import BoardOne from '@com/BoardOne'
import ImgUpload from '@com/ImgUpload'
import TemplateAdd from './components/TemplateAdd'
import { getDoubleNum } from '@common/utility'
import {
  addRecordNoteWeek,
  getWeekRecordForm,
  addRecordProblem,
  addUserRememberTips,
  addRecordProblemLoading,
  addRecordNoteWeekLoading,
  queryCodeInfo,
  selectUserRememberTips,
  queryRoleCodeInfo,
  collectNoteTemplateInfo,
  getRememberWriteRecordTips,
  checkSubmitRecord,
} from '@api/api-documentary.js'
export default {
  name: 'weekBoard',
  components: {
    MyNavBar,
    BoardSound,
    BoardSimple,
    BoardOne,
    ImgUpload,
    TemplateAdd,
  },
  data() {
    return {
      getDoubleNum,
      activeName: 0,
      activeNameNext: 0,
      // 路由传参
      routerQuery: {},
      showTabs: '1',
      activeTabs: '1',
      numersShow: false,
      numersCheck: false,
      collectDiaShow: false,
      checkedCollect: false,
      allData: [
        {
          id: 'workCon',
          title: '本周工作纪实',
          entryCont: '',
          audioList: [],
          required: true,
        },
        {
          id: 'planCon',
          title: '下周工作计划',
          entryCont: '',
          audioList: [],
        },
      ],

      formData: {
        recordName: '周纪实',
        recordId: '',
        formCode: '',
      },
      albumList: [],
      dailyObj: {
        nowWeekList: [],
        nextWeekList: [],
      },

      suggestionList: [], //问题建议

      templateShow: false, //模板页面
      taskList: [], //所属类型
      classifyList: [], //工作分类
      actionShowWork: false, //工作分类,
      actionShowStyle: false, //所属类型,
      selectData: {}, //选择的数据
      isCommit: false,
      tipSubmitShow: false,
      mesDia: '',
      recordTime: '',
      formCode: '', // 表单类型：FORM_V1单框，条目化，单框&条目化
      formContent: {
        recordFileList: [],
      },
      emptyNowWeekList: [
        {
          oneData: [
            {
              id: 'workCon',
              title: '工作内容',
              entryCont: '',
              audioList: [],
              placeholder: '请输入工作内容',
              required: true,
            },
          ],
          workTag: '',
          finishStatus: '1',
          finishPercent: '',
          workClassify: '',
          collectShow: false,
          workClassifyName: '',
          linkId: '',
          id: '',
        },
      ],
      emptyNextWeekList: [
        {
          oneData: [
            {
              id: 'planCon',
              title: '工作计划',
              entryCont: '',
              audioList: [],
              placeholder: '请输入工作计划',
            },
          ],
          workTag: '',
          workClassify: '',
          collectShow: false,
          workClassifyName: '',
          linkId: '',
          id: '',
          finishStatus: '',
          finishPercent: '',
        },
      ],
    }
  },
  computed: {},
  watch: {},
  created() {
    // this.getRememberWriteRecordTips()
    // this.getCodeInfo()
  },
  mounted() {
    this.routerQuery = Object.assign({}, this.$route.query)
    this.pageInit('1')
  },
  activated() {},
  deactivated() {
    // rememberWriteRecordTips({ recordType: 'write_01-01', status: this.showTabs }).then(res => {
    //   console.log('ok')
    // })
  },
  destroyed() {
    if (!this.isCommit) {
      this.temporaryStorage()
    }
  },
  methods: {
    goback() {
      this.$router.go(-1)
    },
    contentJudge(content, indexObj) {
      if (indexObj.type == '1') {
        this.dailyObj.nowWeekList[indexObj.index].collectShow = content.trim() ? true : false
      } else if (indexObj.type == '2') {
        this.dailyObj.nextWeekList[indexObj.index].collectShow = content.trim() ? true : false
      }
    },
    onTabsClick(val) {
      if (this.activeTabs === val) return
      this.activeTabs = val
      // if (this.showTabs == '2') {
      //   //获取展示弹框
      //   selectUserRememberTips({
      //     recordType: 'NOTE_REL_CONTENT_SWITCH',
      //   }).then(res => {
      //     if (res.status == 200) {
      //       this.numersShow = res.data == 1 ? true : false
      //     }
      //   })
      // }
    },
    //收藏成功
    btnCheck() {
      if (this.checkedCollect) {
        this.showNo('NOTE_REL_CONTENT_TEMPLATE_COLLECT')
      }
      this.collectDiaShow = false
    },
    //弹框不在展示
    showNo(typesDialog) {
      addUserRememberTips({
        recordType: typesDialog,
      }).then(res => {
        if (res.status == 200) {
        }
      })
    },
    //切换好的
    numbersCli() {
      if (this.numersCheck) {
        this.showNo('NOTE_REL_CONTENT_SWITCH')
      }
      this.numersShow = false
    },
    //弹框不在展示
    showNo(typesDialog) {
      addUserRememberTips({
        recordType: typesDialog,
      }).then(res => {
        if (res.status == 200) {
        }
      })
    },

    pageInit(type) {
      let that = this
      getWeekRecordForm({
        id: that.routerQuery.id,
        optionUserId: localStorage.userId,
        tenantId: localStorage.tenantId,
      }).then(res => {
        let data = res.data
        that.formData = data

        that.formCode = data.formCode

        if (that.formCode === 'FORM_V1' || that.formCode === 'FORM_V3') {
          that.formContent = data.formV1VO
          that.allData[0].entryCont = data.formV1VO.workCon
          that.allData[0].audioList = data.formV1VO.workAudioList
          that.allData[1].entryCont = data.formV1VO.planCon
          that.allData[1].audioList = data.formV1VO.planAudioList
          that.dealSuggestData(data.formV1VO)
        }
        if (that.formCode === 'FORM_V2' || that.formCode === 'FORM_V3') {
          that.getCodeInfo()
          if (that.formCode === 'FORM_V2') {
            that.formContent = data.formV2VO
          }
          that.dealSuggestData(data.formV2VO)
          if (data.formV2VO.workConList.length == 0) {
            that.dailyObj.nowWeekList = that.emptyNowWeekList
          } else {
            that.dailyObj.nowWeekList = []
            for (let i in data.formV2VO.workConList) {
              let oneweek1 = data.formV2VO.workConList[i]
              that.dailyObj.nowWeekList.push({
                workTag: oneweek1.workTag,
                finishStatus: oneweek1.finishStatus,
                finishPercent: oneweek1.finishPercent,
                workClassify: oneweek1.workClassify,
                id: oneweek1.id,
                linkId: oneweek1.linkId,
                workClassifyName: oneweek1.workClassifyName,
                oneData: [
                  {
                    id: 'workCon',
                    title: '工作内容',
                    entryCont: oneweek1.workContent,
                    audioList: oneweek1.audioList,
                    placeholder: '请输入工作内容',
                    required: true,
                  },
                ],
                collectShow: oneweek1.workContent.trim() ? true : false,
              })
            }
          }
          if (data.formV2VO.planConList.length == 0) {
            that.dailyObj.nextWeekList = that.emptyNextWeekList
          } else {
            that.dailyObj.nextWeekList = []
            for (let i in data.formV2VO.planConList) {
              let oneweek1 = data.formV2VO.planConList[i]
              that.dailyObj.nextWeekList.push({
                workTag: oneweek1.workTag,
                workClassify: oneweek1.workClassify,
                workClassifyName: oneweek1.workClassifyName,
                linkId: oneweek1.linkId,
                id: oneweek1.id,
                finishStatus: oneweek1.finishStatus,
                finishPercent: oneweek1.finishPercent,
                oneData: [
                  {
                    id: 'planCon',
                    title: '工作内容',
                    entryCont: oneweek1.workContent,
                    audioList: oneweek1.audioList,
                    placeholder: '请输入工作计划',
                  },
                ],
                collectShow: oneweek1.workContent.trim() ? true : false,
              })
            }
          }
          if (type === '1') {
            that.activeName = that.dailyObj.nowWeekList.length - 1
            that.activeNameNext = that.dailyObj.nextWeekList.length - 1
          }
        }
        that.recordTime = `(${that.formContent.startDate}-${that.formContent.endDate})`

        that.$nextTick(() => {
          that.showTabs = that.formCode === 'FORM_V2' ? '2' : '1'
        })
      })
    },
    //获取枚举
    getCodeInfo() {
      queryCodeInfo({
        oneParam: 'NOTE_WORK_CLASSIFY',
      }).then(res => {
        this.taskList = []
        res.data.forEach((item, index) => {
          this.taskList.push({ name: item.name, value: item.code })
        })
      })
      queryRoleCodeInfo({
        oneParam: 'NOTE_WORK_TAG',
      }).then(res => {
        this.classifyList = res.data
      })
    },

    classifyTips(index, type) {
      this.actionShowWork = true
      this.selectData = {
        indexData: index,
        types: type,
      }
    },
    workFromPop(index, type) {
      this.actionShowStyle = true
      this.selectData = {
        indexData: index,
        types: type,
      }
    },
    //工作分类的选择
    onSelectWork(item) {
      let i = this.selectData.indexData
      if (this.selectData.types == '1') {
        this.dailyObj.nowWeekList[i].workTag = item.name
      } else if (this.selectData.types == '2') {
        this.dailyObj.nextWeekList[i].workTag = item.name
      }
      this.actionShowWork = false
    },
    //所属类型的选择
    onSelectStyle(item) {
      let i = this.selectData.indexData
      if (this.selectData.types == '1') {
        this.dailyObj.nowWeekList[i].workClassify = item.value
      } else if (this.selectData.types == '2') {
        this.dailyObj.nextWeekList[i].workClassify = item.value
      }
      this.actionShowStyle = false
    },

    //示例与操作
    operateCli() {
      this.$router.push({ path: '/boardOperate' })
    },
    //预览
    viewBoard() {
      this.commitBoard('0', 'annex', 'view')
    },
    // 提交周纪实
    commitBoard(saveStatus, annex, loadstatus) {
      if (saveStatus == 1) {
        let nowWeekList = this.dailyObj.nowWeekList.filter(item => {
          return item.oneData[0].entryCont
        })
        if (nowWeekList.length == 0 && this.allData[0].entryCont.trim() == '') {
          this.$toast.fail(`请填写${this.allData[0].title}！`)
          return false
        } else if (
          nowWeekList.length == 0 &&
          this.allData[0].entryCont.trim() &&
          this.allData[0].entryCont.trim().length < 10
        ) {
          this.$toast.fail(`${this.allData[0].title}必须大于10个字！`)
          return false
        }
      }
      // 问题建议
      if (saveStatus == 1) {
        let reg = /<[^>]+>/g // 去除html标签
        let regs = /&nbsp;/g // 去除空格标签
        for (let i = 0; i < this.suggestionList.length; i++) {
          if (
            this.suggestionList[i].suggestionData[0].entryCont.length != 0 &&
            this.suggestionList[i].suggestionData[0].entryCont.replace(reg, '').replace(regs, '').trim().length <= 5
          ) {
            // let title = i + 1
            // title = title < 10 ? '0' + title : title
            // if (this.suggestionList.length === 1) {
            //   title = ''
            // }
            // this.$toast.fail(`问题建议${title}内容需要超过5个字`)
            this.$toast.fail(`问题建议内容需要超过5个字`)
            return false
          }
        }
      }
      if (saveStatus == 1) {
        checkSubmitRecord({
          id: this.routerQuery.id,
        }).then(res => {
          if (res.code == 0) {
            if (!res.data.flag) {
              this.mesDia = res.data.tips
              this.tipSubmitShow = true
              return
            } else {
              this.$dialog
                .confirm({
                  title: '提示',
                  message: '提交后周纪实内容不可修改,\n您确定提交吗？',
                })
                .then(() => {
                  this.commitRecordNoteWeek(saveStatus)
                })
                .catch(() => {})
            }
          }
        })
      } else {
        this.commitRecordNoteWeek(saveStatus, annex, loadstatus)
      }
    },
    commitRecordNoteWeek(saveStatus, annex, loadstatus) {
      let params = { ...this.formData }
      if (['FORM_V1', 'FORM_V3'].includes(this.formCode)) {
        params.formV1VO = this.formContent
        params.formV1VO.workCon = this.allData[0].entryCont
        params.formV1VO.workAudioList = this.allData[0].audioList
        params.formV1VO.planCon = this.allData[1].entryCont
        params.formV1VO.planAudioList = this.allData[1].audioList
        params.formV1VO.proConList = this.subbmitSuggest()
      }
      if (['FORM_V2', 'FORM_V3'].includes(this.formCode)) {
        if (this.formCode === 'FORM_V2') {
          params.formV2VO = this.formContent
        }
        params.formV2VO.proConList = this.subbmitSuggest()
        let weekNow = []
        let weekNext = []
        //本周多条
        for (let i in this.dailyObj.nowWeekList) {
          let oneweek1 = this.dailyObj.nowWeekList[i]
          weekNow.push({
            audioList: oneweek1.oneData[0].audioList || [],
            finishPercent: oneweek1.finishPercent,
            finishStatus: oneweek1.finishStatus,
            id: oneweek1.id,
            workTag: oneweek1.workTag,
            linkId: oneweek1.linkId,
            workClassify: oneweek1.workClassify,
            workClassifyName: oneweek1.workClassifyName,
            workContent: oneweek1.oneData[0].entryCont,
            workTag: oneweek1.workTag,
          })
        }
        //下周多条
        for (let i in this.dailyObj.nextWeekList) {
          let oneweek1 = this.dailyObj.nextWeekList[i]
          weekNext.push({
            audioList: oneweek1.oneData[0].audioList || [],
            finishPercent: oneweek1.finishPercent,
            finishStatus: oneweek1.finishStatus,
            id: oneweek1.id,
            linkId: oneweek1.linkId,
            workClassify: oneweek1.workClassify,
            workClassifyName: oneweek1.workClassifyName,
            workContent: oneweek1.oneData[0].entryCont,
            workTag: oneweek1.workTag,
          })
        }
        if (saveStatus == 1) {
          weekNow = weekNow.filter(item => {
            return item.workContent
          })
          weekNext = weekNext.filter(item => {
            return item.workContent
          })
        }
        params.formV2VO.workConList = weekNow
        params.formV2VO.planConList = weekNext
      }

      if (loadstatus === 'isload' || loadstatus === 'view') {
        addRecordNoteWeekLoading({
          ...params,
          saveStatus: saveStatus,
        }).then(res => {
          if (annex == 'savePage') {
            this.pageInit('2')
          }
          if (loadstatus === 'view') {
            this.$router.push({
              path: '/boarddetail',
              query: { id: this.$route.query.id, recordType: this.$route.query.recordType, from: 'view' },
            })
          }
          console.log('实时保存')
        })
      } else {
        addRecordNoteWeek({
          ...params,
          saveStatus: saveStatus,
        }).then(res => {
          if (res.code === 0) {
            if (saveStatus == 1) {
              this.$toast.success('提交成功')
              this.isCommit = true
              setTimeout(() => {
                this.$router.go(-1)
              }, 500)
            } else {
              if (!annex) {
                this.$toast.success('暂存成功')
              }
            }
          }
        })
      }
    },

    // 附件暂存
    temporaryStorage() {
      // 调用暂存时，对定时器进行清除并重置
      this.commitBoard('0', 'annex', 'isload')
    },

    // 删除问题建议
    deleteSug(data) {
      if (this.suggestionList.length > 1) {
        this.suggestionList.splice(data, 1)
      }
    },
    // 新增问题建议
    addSug() {
      let obj = {
        suggestionData: [
          {
            id: '',
            title: '问题建议',
            entryCont: '',
            audioList: [],
            isAt: true,
            wordLimit: 300,
          },
        ],
        suggestionalbumList: [],
      }
      this.suggestionList.push(obj)
    },
    // 保存问题建议
    addRecordProblem(saveStatus, annex, loadstatus) {
      let that = this
      let params = {
        noteId: that.routerQuery.id,
        recordProblemList: [],
        saveStatus: saveStatus,
      }
      this.suggestionList.forEach(item => {
        params.recordProblemList.push({
          content: item.suggestionData[0].entryCont,
          contentVideo: item.suggestionData[0].audioList,
          id: item.suggestionId,
          enclosureList: item.suggestionalbumList,
        })
      })
      if (loadstatus === 'isload' || loadstatus === 'view') {
        addRecordProblemLoading(params).then(res => {
          if (res.status === 200) {
            that.commitRecordNoteWeek(saveStatus, annex, loadstatus)
          }
        })
      } else {
        addRecordProblem(params).then(res => {
          if (res.status === 200) {
            that.commitRecordNoteWeek(saveStatus, annex)
          }
        })
      }
    },

    // 添加一行-本周工作计划
    addRowsWeek() {
      this.temporaryStorage()
      this.dailyObj.nowWeekList.push(JSON.parse(JSON.stringify(this.emptyNowWeekList[0])))
      this.activeName = this.dailyObj.nowWeekList.length - 1
    },
    // 取消-本周
    cancelWeek(index) {
      this.$dialog
        .confirm({ title: '提示', message: '您确认删除该条纪实吗？' })
        .then(() => {
          if (index === this.dailyObj.nowWeekList.length - 1) {
            this.activeName = index - 1
          }
          this.dailyObj.nowWeekList.splice(index, 1)
          this.temporaryStorage()
        })
        .catch(() => {})
    },
    //收藏
    collectWeek(row, index) {
      this.collectOne(row)
    },
    //模板添加-本周
    addRowsTemplate() {
      this.temporaryStorage()
      this.selectData = {
        types: '1',
      }
      this.templateShow = true
    },

    // 添加一行-下周工作计划
    addNextWeek() {
      this.temporaryStorage()
      this.dailyObj.nextWeekList.push(JSON.parse(JSON.stringify(this.emptyNextWeekList[0])))
      this.activeNameNext = this.dailyObj.nextWeekList.length - 1
    },
    //取消 -下周
    cancelNextWeek(index) {
      this.$dialog
        .confirm({ title: '提示', message: '您确认删除该条计划吗？' })
        .then(() => {
          if (index === this.dailyObj.nextWeekList.length - 1) {
            this.activeNameNext = index - 1
          }
          this.dailyObj.nextWeekList.splice(index, 1)
          this.temporaryStorage()
        })
        .catch(() => {})
    },
    //收藏-下周
    collectNextWeek(row, index) {
      this.collectOne(row)
    },
    //收藏
    collectOne(row) {
      let objCollect = {}
      for (let i in row.oneData) {
        let oneCollect = row.oneData[i]
        if (oneCollect.required && !oneCollect.entryCont) {
          this.$toast.fail(`${oneCollect.title}不能为空！`)
          return false
        }
        objCollect.workContent = oneCollect.entryCont
        objCollect[`audioList`] = oneCollect.audioList
      }
      let dataCollect = Object.assign(row, objCollect, { templateType: '1' })
      collectNoteTemplateInfo(dataCollect).then(res => {
        if (res.code == 0) {
          //获取展示弹框
          selectUserRememberTips({
            recordType: 'NOTE_REL_CONTENT_TEMPLATE_COLLECT',
          }).then(res => {
            if (res.code == 0) {
              this.collectDiaShow = res.data == 1 ? true : false
              if (!this.collectDiaShow) {
                this.$toast.success('收藏成功')
              }
            }
          })
        }
      })
    },

    //从模板中添加 - 下周
    addNextTemplate() {
      this.temporaryStorage()
      this.selectData = {
        types: '2',
      }
      this.templateShow = true
    },
    //模板中添加-确认
    templateBtn(selectOne) {
      this.templateShow = false
      if (this.selectData.types == '1') {
        let oneChoose = {
          oneData: [
            {
              id: 'workCon',
              title: '工作内容',
              entryCont: selectOne.workContent,
              audioList: [],
              placeholder: '请输入工作内容',
              required: true,
            },
          ],
          workTag: selectOne.workTag,
          finishStatus: selectOne.finishStatus,
          finishPercent: selectOne.finishPercent,
          workClassify: selectOne.workClassify,
          workClassifyName: selectOne.workClassifyName || '',
          linkId: selectOne.linkId || '',
          id: selectOne.id || '',
          collectShow: true,
        }
        this.dailyObj.nowWeekList.push(oneChoose)
        this.activeName = this.dailyObj.nowWeekList.length - 1
      } else if (this.selectData.types == '2') {
        let oneChoose = {
          oneData: [
            {
              id: 'workCon',
              title: '工作内容',
              entryCont: selectOne.workContent,
              audioList: [],
              placeholder: '请输入工作内容',
              required: true,
            },
          ],
          workTag: selectOne.workTag,
          workClassify: selectOne.workClassify,
          collectShow: true,
          finishStatus: selectOne.finishStatus || '',
          finishPercent: selectOne.finishPercent || '',
          workClassifyName: selectOne.workClassifyName || '',
          linkId: selectOne.linkId || '',
          id: selectOne.id || '',
        }
        this.dailyObj.nextWeekList.push(oneChoose)
        this.activeNameNext = this.dailyObj.nextWeekList.length - 1
      }
    },
    workClassify(val) {
      let arr = this.taskList.filter(item => {
        return val === item.value
      })
      return (arr[0] && arr[0].name) || '请选择'
    },
    getRememberWriteRecordTips() {
      getRememberWriteRecordTips({ recordType: 'write_01-01' }).then(res => {
        if (res.status === 200) {
          this.showTabs = String(res.data)
          this.activeTabs = String(res.data)
        }
      })
    },

    dealSuggestData(data) {
      const that = this
      const arr = []
      // 工作建议
      if (data.proConList.length > 0) {
        let list = data.proConList
        list.forEach(item => {
          arr.push({
            suggestionData: [
              {
                id: '问题建议',
                title: '问题建议',
                entryCont: item.proCon,
                audioList: item.proAudioList,
                isAt: true,
                wordLimit: 300,
              },
            ],
            suggestionalbumList: item.proFileList,
            suggestionId: item.id,
          })
        })
      } else {
        arr.push({
          suggestionData: [
            {
              id: '',
              title: '问题建议',
              entryCont: '',
              audioList: [],
              isAt: true,
              wordLimit: 300,
            },
          ],
          suggestionalbumList: [],
          suggestionId: '',
        })
      }
      that.suggestionList = arr
    },
    subbmitSuggest() {
      const arr = []
      this.suggestionList.forEach(item => {
        if (item.suggestionalbumList.length || item.suggestionData[0].entryCont) {
          arr.push({
            proAudioList: item.suggestionData[0].audioList,
            proCon: item.suggestionData[0].entryCont,
            proFileList: item.suggestionalbumList,
          })
        }
      })
      return arr
    },
  },
}
</script>

<style lang="scss" scoped>
.board_write {
  /deep/.van-tab__text {
    line-height: 30px;
    font-size: 13px;
  }
  font-size: 12px;
  .board_w_title {
    position: relative;
    background-color: #ddd;
    height: 35px;
    // font-size: 14px;
    padding: 0 10px;
    .title_center {
      text-align: center;
      line-height: 35px;
      span {
        margin-right: 8px;
      }
      .tabs_active {
        color: #cba76d;
      }
    }
    .tit_view {
      line-height: 25px;
      height: 25px;
      width: 40px;
      position: absolute;
      right: 8px;
      top: 3px;
      background-color: #0f61d5;
      border-radius: 4px;
      display: flex;
      align-items: center;
      justify-content: center;
    }
  }
  .board_write_content {
    padding: 10px;
    padding-bottom: 60px;
    background-color: #f0f0f0;
    .return-box {
      margin-bottom: 5px;
      color: #f56c6c;
      background: #fef0f0;
      padding: 5px;
      font-size: 14px;
    }
    .one_board_add {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 36px;
      .color_blue {
        cursor: pointer;
        border: 1px solid #dcdfe6;
        padding: 3px 5px;
        display: inline-block;
        margin-left: 10px;
        color: #4b79bb;
        font-weight: bold;
        &:hover {
          box-shadow: 2px 4px 12px 1px rgba(0, 0, 0, 0.4);
        }
      }
    }
    .two_title1 {
      display: flex;
      // justify-content: space-between;
      align-items: center;
      padding: 16px 14px 3px;
      .two_title1_left {
        font-size: 14px;
        font-weight: bold;
        color: #a57d60;
        background-image: linear-gradient(#ffffff 50%, #f9f1e8);
      }
    }
    .now_week {
      .no_collapse {
        /deep/ .van-collapse-item__title--expanded {
          .van-icon-arrow {
            display: none;
          }
        }
      }
      /deep/.van-collapse-item {
        .van-collapse-item__title {
          padding: 15px 16px;
          position: relative;
          .now_week_title_tip {
            position: absolute;
            left: 0;
            top: 0;
            line-height: 1;
            .icon-jinxingzhong {
              font-size: 30px;
              color: #d80a06;
            }
          }
        }
        .van-collapse-item__content {
          padding-top: 0;
          padding-bottom: 0;
        }
        .list_box {
          padding: 0;
          .list_text_box {
            padding: 5px 0;
          }
          .scroe_input {
            padding-left: 0;
          }
        }
      }
      .now_week_one {
        padding: 0 5px;
        border-bottom: 2px solid #f0f0f0;
      }
      .now_week_title {
        display: flex;
        justify-content: space-between;
        align-items: center;
      }
      .one {
        position: relative;
        .now_week_title_r {
          position: absolute;
          right: 0;
        }
      }
      .now_week_title_left {
        font-weight: bold;
        // font-size: 14px;
        flex: 1;
        width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        .week_title_tips {
          background-image: linear-gradient(#ffffff 50%, #f9f1e8);
        }
        .week_title {
          margin: 0 16px;
        }
      }
      .now_week_title_r {
        display: flex;
        color: #4b79bb;
        font-size: 12px;
        span {
          display: flex;
          align-items: center;
          padding-right: 8px;
          margin-right: 15px;
        }
      }
      .week_input_data {
        display: flex;
        align-items: center;
        .week_text {
          border-top: 1px solid #f0f0f0;
          flex: 1;
        }
        .pad_left_board {
          padding-left: 9px;
        }
      }

      .week_text {
        display: flex;
        align-items: center;
        padding: 5px 0;
        .week_text_title {
          color: #333333;
          font-size: 12px;
        }
        .week_text_r {
          flex: 1;
          text-align: right;
          span {
            margin-right: 8px;
          }
          .text_r_icon {
            color: #999999;
            font-size: 12px;
          }
          .van-cell {
            justify-content: flex-end;
            .van-cell__value {
              text-align: right;
              font-size: 12px;
            }
          }
          .placeholder {
            .van-cell__value--alone {
              color: #c8c9cc;
            }
          }
          /deep/.van-radio-group {
            .van-radio {
              margin-left: 20px;
              font-size: 12px;
              .van-radio__icon {
                font-size: 14px;
              }
              .van-radio__icon--checked .van-icon {
                background-color: #5f7290;
                border-color: #5f7290;
              }
            }
          }
        }
        .week_input_r {
          flex: 1;
          .week_fied_input {
            padding: 0 5px;
            width: 100%;
            // height: 30px;
            // line-height: 30px;
            font-size: 12px;
            resize: none;
          }
          /deep/.van-field__control {
            color: #333333;
            text-align: right;
          }
        }
      }
    }
    .tem_operate {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      // font-size: 14px;
      color: #004db6;
      padding: 0 16px 8px;
      line-height: 15px;
    }
    .week_box {
      background-color: #ffffff;
      box-shadow: 0 0 10px 0 rgba(4, 0, 0, 0.15);
      width: 100%;
      margin-bottom: 10px;
      border-radius: 5px;
      .now_week_add {
        display: flex;
        justify-content: center;
        padding-bottom: 10px;
        margin-top: 8px;
        .week_add-one {
          display: flex;
          align-items: center;
          justify-content: center;
          color: #004db6;
          // font-size: 14px;
          padding: 5px 0;
          width: 125px;
          border: 1px solid #004db6;
          border-radius: 5px;
          span {
            margin-left: 8px;
          }
        }
        .m-add_l {
          margin-right: 10px;
        }
      }
    }
  }
  // 问题建议
  .suggestion_box {
    .suggestion {
      .suggestion_annex {
        background-color: #fff;
        // margin-bottom: 10px;
        .img_video {
          padding: 10px 16px;
          border-bottom: 1px solid #f0f0f0;
        }
        // 文件上传
        .up_file {
          padding: 20px 16px 0 16px;
        }
      }
    }
    .add_box {
      background-color: #fff;
      padding: 5px 15px;
      color: #004db6;
      display: flex;
      justify-content: center;
      .add_btn {
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 14px;
        padding: 5px 15px;
        border: 1px solid #004db6;
        border-radius: 5px;
        width: 265px;
        span {
          margin-left: 8px;
        }
      }
    }
  }
  .sugg_item {
    background-color: #ffffff;
    padding: 15px 0 5px;
    margin-top: 10px;
    border-radius: 5px;
    overflow: hidden;
    .list_text_title {
      padding: 0 14px;
    }
  }
  .list_text_title {
    font-size: 14px;
    font-weight: bold;
    color: #a57d60;
    margin-bottom: 6px;
    .text {
      background-image: linear-gradient(#ffffff 50%, #f9f1e8);
    }
  }
  /deep/.van-popup {
    padding: 10px 0;
    .sharePerson {
      width: 100%;
      display: flex;
      flex-direction: column;
      margin-bottom: 8px;
      font-size: 14px;
      line-height: 25px;
    }
    .van-sidebar {
      width: 60%;
      min-width: 60%;
    }
    .van-tree-select__nav {
      .van-tree-select__nav-item {
        padding: 10px;
        line-height: 10px;
        @include ellipsis;
      }
    }
    .van-tree-select__content {
      width: 100%;
      .van-tree-select__item {
        width: 100%;
        padding: 10px;
        line-height: 10px;
        .van-tree-select__selected {
          transform: translateY(-50%);
          position: absolute;
        }
      }
    }
    .btn {
      display: flex;
      justify-content: space-around;
      align-items: center;
      font-size: 18px;
      width: 100%;
      color: #323233;
      div {
        width: 50%;
        text-align: center;
        height: 40px;
        line-height: 40px;
      }
      .confirm {
        color: #ee0a24;
      }
    }
  }
  // 附件
  .annex {
    background-color: #fff;
    margin: 10px 0;
    border-radius: 5px;
    padding: 20px 5px 10px;

    .img_video {
      padding: 0 11px;
      border-bottom: 1px solid #f0f0f0;
    }

    // 文件上传
    .up_file {
      padding: 20px 16px 0 16px;
    }
  }
  /deep/.tip_dialog {
    // font-size: 14px;
    .van-dialog__header {
      padding-top: 12px;
      font-weight: bold;
      font-size: 16px;
    }
    .van-dialog__content {
      padding: 16px 21px 20px;
      .push_dia_box_content {
        line-height: 2;
        .icon_warn {
          color: #ee792f;
          font-size: 14px;
        }
      }

      .push_dia_commit {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-top: 12px;
        font-size: 14px;
        .van-checkbox {
          padding: 5px;
        }
        .van-checkbox__icon .van-icon {
          font-size: 16px;
        }
        .van-checkbox__icon--checked .van-icon {
          background-color: #ee0a24;
          border-color: #ee0a24;
        }
        .push_dia_commit_btn {
          color: #ee0a24;
          padding: 0 5px;
        }
      }
    }
  }
}
</style>
